package com.ejuornal.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.Page;
import com.ejuornal.bean.SysMsg;
import com.ejuornal.dao.SysMsgDao;
import com.ejuornal.service.SysMsgService;
@Component("sysMsgService")
public class SysMsgServiceImpl implements SysMsgService{
    private SysMsgDao sysMsgDao;

    
    
    public SysMsgDao getSysMsgDao() {
        return sysMsgDao;
    }
    @Resource(name="sysMsgDao")
    public void setSysMsgDao(SysMsgDao sysMsgDao) {
        this.sysMsgDao = sysMsgDao;
    }
    public void add(SysMsg sysMsg) {
        sysMsg.setSmSender("管理员");
        sysMsg.setSmType("0");
        String sql = "INSERT INTO t_sys_msg(smTitle, smContent, smSender, smType,smDate) value(?, ?, ?, ?,now())";
        sysMsgDao.add(sql, new Object[]{
                 sysMsg.getSmTitle(), 
                 sysMsg.getSmContent(),
                 sysMsg.getSmSender(), 
                 sysMsg.getSmType()}
        );
    }
    
    public Page<SysMsg> findByDate(int page, String url) {
        String hsql= "order by smDate";
        return sysMsgDao.find((page - 1) * 10, url, hsql, null);
    }
    
    public SysMsg Detail(int smId) {
        return sysMsgDao.find(smId);
    }
    
	@Override
	public void delete(int[] smIds) {
		// TODO Auto-generated method stub
		String sql = "delete from t_sys_msg where smId = ?";
		sysMsgDao.batchDelete(sql, smIds);
	}
	 public Page<SysMsg> findByStatus(String status, int user_id, int current_record, String url) {
	    return sysMsgDao.findByStatus(status, user_id, current_record,url);
	}
	
	 public boolean findNew(int user_id) {
	     return sysMsgDao.findNew(user_id);
	 }
	@Override
	public SysMsg findById(int messageId) {
		return sysMsgDao.find(messageId);
	}
	
}
